package com.hw.ui.main;

import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hw.HWApp;
import com.hw.R;
import com.hw.base.activity.BaseActivity_noMVP;
import com.hw.base.util.Util;
import com.hw.dialog.ChooseDialog;
import com.hw.ui.casecode_replace.CaseCodeReplaceActivity;
import com.hw.ui.code_replace.CodeReplaceActivity;
import com.hw.ui.relation_info.RelationInfoActivity;
import com.hw.ui.upload_data.UploadActivity;
import com.shelwee.update.UpdateHelper;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends BaseActivity_noMVP {
    private String tag = "MainActivity";
    @Bind(R.id.imageView4)
    ImageView imageView4;
    @Bind(R.id.text4)
    TextView text4;
    @Bind(R.id.ll4)
    LinearLayout ll4;
    @Bind(R.id.tvright)
    TextView tvright;
    @Bind(R.id.imageView1)
    ImageView imageView1;
    @Bind(R.id.text1)
    TextView text1;
    @Bind(R.id.ll1)
    LinearLayout ll1;
    @Bind(R.id.imageView2)
    ImageView imageView2;
    @Bind(R.id.text2)
    TextView text2;
    @Bind(R.id.ll2)
    LinearLayout ll2;
    @Bind(R.id.imageView3)
    ImageView imageView3;
    @Bind(R.id.text3)
    TextView text3;
    @Bind(R.id.ll3)
    LinearLayout ll3;
    @Bind(R.id.iv_title_left)
    ImageView ivTitleLeft;
    @Bind(R.id.tv_title)
    TextView tvTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        tvTitle.setText("主页");
        UpdateHelper updateHelper = new UpdateHelper.Builder(this)
                .checkUrl(HWApp.sSharedPreferences.getString(Util.addk, "") + Util.url_appupdate,"com.hw")
                .isAutoInstall(true) //设置为false需在下载完手动点击安装;默认值为true，下载后自动安装。
                .build();
        updateHelper.check();
    }

    @OnClick({R.id.iv_title_left, R.id.ll1, R.id.ll2, R.id.ll3, R.id.ll4})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_title_left:
                ChooseDialog nDialog = new ChooseDialog(this, "退出", R.style.Dialog1, new ChooseDialog.PriorityListener() {
                    @Override
                    public void setActivityText() {
                        finish();
                    }
                });
                WindowManager.LayoutParams lp = nDialog.getWindow().getAttributes();
                lp.gravity = Gravity.CENTER;
                nDialog.setCanceledOnTouchOutside(false);
                nDialog.show();
                break;
            case R.id.ll1:
                intentToActivityWithoutParameter(this, RelationInfoActivity.class);
                break;
            case R.id.ll2:
                intentToActivityWithoutParameter(this, CaseCodeReplaceActivity.class);
                break;
            case R.id.ll3:
                intentToActivityWithoutParameter(this, CodeReplaceActivity.class);
                break;
            case R.id.ll4:
                intentToActivityWithoutParameter(this, UploadActivity.class);
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            ChooseDialog nDialog = new ChooseDialog(this, "退出", R.style.Dialog1, new ChooseDialog.PriorityListener() {
                @Override
                public void setActivityText() {
                    finish();
                }
            });
            WindowManager.LayoutParams lp = nDialog.getWindow().getAttributes();
            lp.gravity = Gravity.CENTER;
            nDialog.setCanceledOnTouchOutside(false);
            nDialog.show();
        }
        return super.onKeyDown(keyCode, event);
    }
}
